#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>
int main()
{
	int m, n;
	scanf("%d %d", &m, &n);

	int tmp = m % n;
	while (tmp)
	{
		m = n;
		n = tmp;
		tmp = m % n;
	}

	printf("%d", n);
	return 0;
}